package CS4310.csueb.visual;
///////////////////////////////////////////////////////////////////////////
//class Tile Panel 
//
//Displays a Tile on the Map
//
//@author Brian L. Donat
//Created 2011-11-15 from MapPanel Code as Example
//
///////////////////////////////////////////////////////////////////////////

import java.awt.image.BufferedImage;
import java.io.*;
import java.awt.*;
import javax.imageio.*;
import javax.swing.*; 

///////////////////////////// class maps /////////////////////////////////
public class TilePanel extends JPanel
{

  private BufferedImage img;
  private Graphics g;
  //private static final long serialVersionUID = -3357275291340439271L;
  
  
//********* default constructor **********//  
  public TilePanel() 
  {   
	  setLayout(null);
	  setBounds(0, 0, 100, 100);
  }

//******* overloaded constructor *********//
//takes a file name for an image and map dimensions   
  public TilePanel(String filename) 
  {   
	  this();
	  loadAndPaint(filename);
  }
  
  
//************* loadAndPaint() **************/
  public void loadAndPaint(String filename)
  { 
	  //reads in image file to BufferedImage
	  try {
	      img = ImageIO.read(new File(filename));
	      } catch (IOException e) {}
	  //converts BufferedImage to Graphics2d 
	  g = img.getGraphics();
  }


//********* override paintComponent() *********/ 
  public void paintComponent(Graphics g)
  { 
	  super.paintComponent(g);

	  if(img != null) {
		  g.drawImage(img, 0, 0, this);
	  } 
  }
}
  